﻿var m_flag_arr = new Array(); 	//	已选中数组
var Major = {
    // 专业列表
    init: function () {
        var _str = '', _id = '';
        if (m_flag_arr.length > 0) {
            for (var i in m_flag_arr) {
                if (!m_flag_arr.hasOwnProperty(i)) {
                    continue;
                }
                _str += ',' + m_a[m_flag_arr[i]];
                _id += ',' + m_flag_arr[i];
            }
            $('#txtmajor').val(_str.substring(1));
            $('#FuntypeID').val(_id.substring(1));
        }
    },
    Show: function (num) {
        var output = '', flag, output2 = '';
        for (var i in m_flag_arr) {
            if (!m_flag_arr.hasOwnProperty(i)) {
                continue;
            }
            output2 += '<li class="Major' + m_flag_arr[i] + ' chkON" onclick="Major.Chk(\'' + m_flag_arr[i] + '\','+num+')">' + m_a[m_flag_arr[i]] + '</li>';
        }
        $('#MajorSelected dd').html(output2);

        for (var i in m_a) {
            if (!m_a.hasOwnProperty(i)) {
                continue;
            }
            if (i.substring(2) == '00') {
                output += '<li onclick="Major.SubLayer(\'' + i + '\','+num+')">' + m_a[i] + '</li>';
            }
        }

        $('#drag').width('670px');
        $('#MajorList').html('<ul>' + output + '</ul>');
        $('#MajorSelected dd').html(output2);

        // 鼠标悬停变色
        $('#MajorAlpha li').hover(function () { $(this).addClass('over') }, function () { $(this).removeClass('over') });
        // 点击弹出子菜单
        $('#MajorList li').click(function (e) { $("#sublist").css({ top: e.pageY - 4, left: e.pageX - 4 }).hover(function () { $(this).show() }, function () { $(this).hide() }) })
    },
    // 子专业 悬浮菜单
    SubLayer: function (id,num) {
        var output = '', width, flag;
        var myid = id.substr(0, 2);
        var len = 0;
        for (var i in m_a) {
            if (!m_a.hasOwnProperty(i)) {
                continue;
            }
            if (i.substr(0, 2) == myid) {
                flag = in_array(i, m_flag_arr) ? ' chkON' : '';
                if (i.substr(2) == '00') {
                    output += '<h4 onclick="Major.Chk(\'' + id + '\','+num+')"><a href="javascript:" class="Major' + id + flag + '">' + m_a[id] + '</a></h4>';
                } else {
                    output += '<li><a href="javascript:" class="Major' + i + flag + '" onclick="Major.Chk(\'' + i + '\',' + num + ')">' + m_a[i] + '</a></li>';
                    len++;
                }
            }
        }
        width = len > 10 ? 440 : 220;
        output = '<div id="sub_major"><ul style="width:' + width + 'px">' + output + '</ul></div>';
        $("#sublist").html(output).show();
    },
    Chk: function (id,num) {
        if (!in_array(id, m_flag_arr)) {
            if (id.substr(2) == '00') {	// 选中父类清除子类
                for (var i in m_a) {
                    if (!m_a.hasOwnProperty(i)) {
                        continue;
                    }
                    if (i.substr(0, 2) == id.substr(0, 2)) {
                        if (in_array(i, m_flag_arr)) this.del(i);
                    }
                }
            } else {	// 选中子类清除父类
                var myid;
                myid = id.substr(0, 2) + '00';
                if (in_array(myid, m_flag_arr)) this.del(myid);
            };

            if (m_flag_arr.length < num) {
                m_flag_arr[m_flag_arr.length] = id;
                var html = '<li class="Major' + id + '" onclick="Major.Chk(\'' + id + '\')">' + m_a[id] + '</li>';
                $('#MajorSelected dd').append(html);
                $('.Major' + id).addClass('chkON');
                $('#MajorSelected li').hover(function () { $(this).addClass('over') }, function () { $(this).removeClass('over') });
            } else {
                alert('您最多能选择'+num+'项');
                return false;
            }
        } else {
            this.del(id)
        }
    },
    del: function (id) {
        for (var i in m_flag_arr) {
            if (!m_flag_arr.hasOwnProperty(i)) {
                continue;
            }
            if (m_flag_arr[i] == id) m_flag_arr.splice(i, 1); ;
        }
        $('#MajorSelected .Major' + id).remove();
        $('.Major' + id).removeClass('chkON');
    },
    // 确定
    confirm: function () {
        var funStr = '', fun_Id = '';
        for (var i in m_flag_arr) {
            if (!m_flag_arr.hasOwnProperty(i)) {
                continue;
            }
            funStr += ',' + m_a[m_flag_arr[i]];
        }
        funStr = funStr.substring(1) ? funStr.substring(1) : '';
        $('#txtmajor').val(funStr);
        $('#FuntypeID').val(m_flag_arr);
        boxAlpha();
    },
/* ****************************** 单选 ********************************* */
	// 单选输出
	Show2 : function(){
		var output='',flag,output2='';
		for (var i in m_a) {
		    if (!m_a.hasOwnProperty(i)) {
		        continue;
		    }
			if(i.substring(2)=='00'){
				output+='<li onclick="Major.SubLayer2(\''+i+'\')">'+m_a[i]+'</li>';
			}
		}
		$('#drag').width('670px');
		$('#MajorList').html('<ul>'+output+'</ul>');
		// 鼠标悬停变色
		$('#MajorAlpha li').hover(function(){$(this).addClass('over')},function(){$(this).removeClass('over')});
		// 点击弹出子菜单
		$('#MajorList li').click(function(e){$("#sublist").css({top:e.pageY-4,left:e.pageX-4}).hover(function(){$(this).show()},function(){$(this).hide()})})
	},
	// 子专业 悬浮菜单
	SubLayer2 : function(id){
		var output='',width;
		var myid=id.substr(0,2);
		var len=0;
		for (var i in m_a) {
		    if (!m_a.hasOwnProperty(i)) {
		        continue;
		    }
			if(i.substr(0,2)==myid){
				if(i.substr(2)=='00'){
					output+='<h4 onclick="Major.Chk2(\''+id+'\')"><a href="javascript:">'+m_a[id]+'</a></h4>';
				}else{
					output+='<li><a href="javascript:" onclick="Major.Chk2(\''+i+'\')">'+m_a[i]+'</a></li>';
					len++;
				}
			}
		}
		width=len>10?440:220;
		output='<div id="sub_major" class="radio"><ul style="width:'+width+'px">'+output+'</ul></div>';
		$("#sublist").html(output).show();
	},
	Chk2 : function(id){
	    $('#txtmajor').val(m_a[id]);
		$('#MajorID_2').val(id);
		$("#sublist").empty().hide();
		boxAlpha();
	}
}
// 单选
function majorSelect_2(){
	var dragHtml ='<div id="MajorAlpha">';			//职能类别
		dragHtml+='		<div id="MajorList"></div>';	//职能类别列表
		dragHtml+='</div>';
	$('#drag_h').html('<b>请选择专业</b><span onclick="boxAlpha()">关闭</span>');
	$('#drag_con').html(dragHtml);
	Major.Show2();
	boxAlpha();
	draglayer();
}
//多选
function majorSelect(num) {    
    var dragHtml = '<div id="MajorAlpha">'; 		//职能类别
    dragHtml += '		<dl id="MajorSelected"><dt>已选专业类别：</dt><dd></dd></dl>';
    dragHtml += '		<div id="MajorList"></div>'; //职能类别列表
    dragHtml += '</div>';
    $('#drag_h').html('<b>请选择专业类别（您最多能选择'+num+'项）</b><span onclick="Major.confirm()">确定</span>');
    $('#drag_con').html(dragHtml);
    Major.Show(num);
    boxAlpha();
    draglayer();
}
function getmyids(mname) {
    var ids = new Array();
    var ms = mname.split(',');
    for (var mm in ms) {
        if (!ms.hasOwnProperty(mm)) {
            continue;
        }
        for (var m in m_a) {
            if (!m_a.hasOwnProperty(m)) {
                continue;
            }
            if (m_a[m] == ms[mm])
                ids[ids.length] = m; ;
        }
    }
    return ids;

}